<project name="tutorial" default="dist" basedir=".">

  <description>Thrift actionscript 3.0 tutorial.</description>

  <property name="gen" location="gen-as3" />
  <property name="src" location="src" />
  <property name="thrift.src" location="../../lib/as3/src/" />
  <property name="dist" location="dist" />

  <property name="final.name" value="as3-tutorial" />
  <property name="swf.name" value="${dist}/${final.name}.swf" />

  <target name="flex.check" unless="FLEX_HOME">
    <fail message='You must set the FLEX_HOME property pointing to your flex SDK, eg. ant -DFLEX_HOME="/Applications/Adobe Flex Builder 3/sdks/3.2.0"'/>
  </target>

  <target name="flex.init" depends="flex.check" unless="flex.finished">
    <taskdef resource="flexTasks.tasks" classpath="${FLEX_HOME}/ant/lib/flexTasks.jar" />
    <property name="flex.finished" value="true"/>
  </target>

  <target name="init">
    <tstamp />
    <mkdir dir="${dist}"/>
  </target>

  <target name="dist" depends="generate, flex.init, init">
    <mxmlc output="${swf.name}" file="${src}/CalculatorUI.as">
      <source-path path-element="${gen}" />
      <source-path path-element="${src}" />
      <source-path path-element="${thrift.src}" />
    </mxmlc>
  </target>

  <target name="generate">
    <!-- Generate the thrift gen-java source -->
    <exec executable="../../compiler/cpp/thrift" failonerror="true">
      <arg line="--gen as3 ../shared.thrift"/>
    </exec>
    <exec executable="../../compiler/cpp/thrift" failonerror="true">
      <arg line="--gen as3 ../tutorial.thrift"/>
    </exec>
  </target>

  <target name="clean">
    <delete dir="${gen}"/>
    <delete dir="${dist}" />
  </target>

</project>
